home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-01-29 | 4.4 KB | 151 lines | [TEXT/IGR0] |
- #pragma rtGlobals=1
-
- | This procedure file creates a control panel that makes it easy to
- | Integrate or Differentiate XY data.
- |
- | The code here assumes you have your data graphed using the left
- | and bottom axes. If you do not choose to replace the original data, the new
- | data is plotted vs the right an bottom axes.
- |
- | Wish list:
- | Remember its settings through invocations
- | Check for various error conditions
- | Check to see on which axes the data is plotted rather than assuming left and bottom
- | Operate on a sub-range of data
- | Allow for operations on data not shown in the top graph
- |
- | Larry Hutchinson 950228
- || Version 1.1, Larry Hutchinson 950925
- || Chagned to be Data Folder and Liberal Names aware.
-
- Macro IntDiffXY()
- NewDataFolder/O root:Packages
- if( !DataFolderExists("root:Packages:WMIntDiffXY") )
- NewDataFolder root:Packages:WMIntDiffXY
- Variable/G root:Packages:WMIntDiffXY:gNumIntPnts= 100
- endif
- XYOperationPanel()
- End
-
-
- Function BProcXYDone(ctrlName) : ButtonControl
- String ctrlName
-
- DoWindow/K $WinName(0, 64)
- KillDataFolder root:Packages:WMIntDiffXY
- End
-
-
- Function BProcXYDefault(ctrlName) : ButtonControl
- String ctrlName
-
- ControlInfo popy
- Wave w= TraceNameToWaveRef("", S_Value)
- NVAR np= root:Packages:WMIntDiffXY:gNumIntPnts
- np= numpnts(w)*5
- End
-
- Function BProcXYDoIt(ctrlName) : ButtonControl
- String ctrlName
-
- ControlInfo popy
- String yWaveName= S_Value
-
- ControlInfo popinterp
- variable method= V_value
-
- ControlInfo popXYOp
- variable doIntegrate= V_value==1
-
- ControlInfo popOpts
- Variable option= V_value
-
- Wave wy= TraceNameToWaveRef("", yWaveName)
- Wave wx= XWaveRefFromTrace("", yWaveName)
- if( (WaveExists(wy)==0) %| (WaveExists(wx)==0) )
- DoAlert 0,"Can't find waves"
- return 0 || ***** error exit
- endif
-
- yWaveName= NameOfWave(wy)
- String xWaveName= NameOfWave(wx)
-
- String wWaveName= "int_"+yWaveName
- NVAR gNumIntPnts= root:Packages:WMIntDiffXY:gNumIntPnts
-
- String savDF= GetDataFolder(1) || save current data folder
- SetDataFolder GetWavesDataFolder(wy, 1) || we will ASSUME x is in same DF
- || we do this so Interpolate will create output in same DF
-
- string cmd,format = "Interpolate/N=(%d)/T=%d/Y=%s %s /X=%s"
- sprintf cmd, format, gNumIntPnts, method,wWaveName, yWaveName, xWaveName
- Execute cmd
- Wave ww= $wWaveName
- SetDataFolder savDF || the rest uses wave references so CDF is irrelevant
-
- if(doIntegrate )
- Integrate/T ww
- else
- Differentiate ww
- endif
-
- do
- CheckDisplayed/A $wWaveName
- Variable wwIsDisplayed= V_Flag==1
- if( option == 1 )
- if( !wwIsDisplayed )
- AppendToGraph/R ww
- endif
- break
- endif
- if( option == 2 )
- Duplicate/O ww, intxyTmp
- Duplicate/O wy,ww
- ww= intxyTmp(wx)
- KillWaves intxyTmp
- if( !wwIsDisplayed )
- AppendToGraph/R ww vs wx
- endif
- break
- endif
- if( option == 3 )
- wy= ww(wx)
- if( wwIsDisplayed )
- RemoveFromGraph $wWaveName | this is a trace instance, not a wave ref
- endif
- KillWaves ww
- endif
- while(0)
- End
-
- Proc XYOperationPanel()
- PauseUpdate; Silent 1 | building window...
- NewPanel /W=(334,151,606,343)
- ModifyPanel cbRGB=(65535,54611,49151)
- SetDrawLayer UserBack
- SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
- DrawText 72,19,"Operation:"
- SetDrawEnv rounding= 20
- DrawRRect 23,35,235,67
- SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
- DrawText 94,83,"Interpolation: "
- SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
- DrawText 66,138,"Options:"
- SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
- DrawText 67,50,"Y data:"
- SetDrawEnv fname= "Geneva",fsize= 10,textxjust= 2,textyjust= 1
- DrawText 78,110,"# points"
- PopupMenu popy,pos={73,40},size={54,19}
- PopupMenu popy,mode=1,value= #"TraceNameList(\"\",\";\",1)"
- PopupMenu popinterp,pos={98,74},size={66,19},mode=1,value= #"\"Linear;Spline\""
- SetVariable setvarnpts,pos={84,103},size={60,15},title=" "
- SetVariable setvarnpts,limits={20,10000,10},value= root:Packages:WMIntDiffXY:gNumIntPnts
- Button buttonDefault,pos={147,101},size={63,20},proc=BProcXYDefault,title="Default"
- PopupMenu popOpts,pos={71,128},size={161,19}
- PopupMenu popOpts,mode=1,value= #"\"Evenly spaced result;At same X values;Replace Y Data\""
- Button buttonDoIt,pos={26,156},size={50,20},proc=BProcXYDoIt,title="Do It"
- Button buttonDone,pos={202,155},size={50,20},proc=BProcXYDone,title="Done"
- PopupMenu popXYOp,pos={76,11},size={89,19}
- PopupMenu popXYOp,mode=1,value= #"\"Integrate;Differentiate\""
- EndMacro
-